package com.sunlands.zlcx.usercenter.repository;

import com.sunlands.zlcx.usercenter.domain.TargetDO;
import com.sunlands.zlcx.usercenter.domain.UsersDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface TargetRepository extends JpaRepository<TargetDO, Long> {

    @Transactional
    @Modifying
    @Query(value = "update tz_target set status = ?2 , parent_name = ?3  where parent_id = ?1 " ,nativeQuery = true)
    int updateTarget(Long parentId, Integer status, String parentName);

    @Query(value = "select * from tz_target order by orders asc ", nativeQuery = true)
    List<TargetDO>  findAllOrderByOrdersAsc();

    List<TargetDO>  findAllByParentIdIn(List<Long> parentIds);

    int countByTargetName(String targetName);
}

